﻿#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>

int missingNumber(int* nums, int numsSize) {
    int i = 0;
    int sumTotal = 0;
    int sumLose = 0;

    for (i = 0; i <= numsSize; i++)
    {
        sumTotal += i;
    }
    int j = 0;
    for (j = 0; j < numsSize; j++)
    {
        sumLose += nums[j];
    }
    return sumTotal - sumLose;
}

int main() {
    // 测试用例数组
    struct TestCase {
        int nums[10];
        int size;
        int expected;
    } testCases[] = {
        {{3, 0, 1}, 3, 2},           // 基础情况
        {{0, 1, 2, 3}, 4, 4},        // 缺失最后一个数
        {{1, 2, 3}, 3, 0},           // 缺失第一个数
        {{0, 1, 3, 4}, 4, 2},        // 缺失中间数
        {{0}, 1, 1},                 // 单个元素
        {{1}, 1, 0},                 // 单个元素缺失0
        {{9,6,4,2,3,5,7,0,1}, 9, 8}, // 较大数组
        {{0,1,2,4,5,6}, 6, 3}        // 连续数组缺失中间
    };

    int testCount = sizeof(testCases) / sizeof(testCases[0]);

    printf("缺失数字测试:\n");
    for (int i = 0; i < testCount; i++) {
        int result = missingNumber(testCases[i].nums, testCases[i].size);
        printf("测试%d: 期望=%d, 实际=%d %s\n",
            i + 1, testCases[i].expected, result,
            result == testCases[i].expected ? "✓" : "✗");
    }

    return 0;
}